//
//  LoginViewController.m
//  ZZRAC
//
//  Created by 赵梁 on 2018/11/4.
//  Copyright © 2018 layzhao. All rights reserved.
//

#import "LoginViewController.h"

#import <ReactiveObjC.h>

@interface LoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *nameTF;
@property (weak, nonatomic) IBOutlet UITextField *passwordTF;
@property (weak, nonatomic) IBOutlet UIButton *loginButton;


@property (nonatomic, copy) NSString* username;//!<

@property (nonatomic, copy) NSString* password;//!<
@property (nonatomic, copy) NSString* passwordConfirmation;//!<

@property (nonatomic, assign) BOOL createEnabled;//!<

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    [RACObserve(self, username) subscribeNext:^(NSString *newName) {
//        NSLog(@"%@", newName);
//    }];
//    [[RACObserve(self, username)
//      filter:^(NSString *newName) {
//          return [newName hasPrefix:@"j"];
//      }]
//     subscribeNext:^(NSString *newName) {
//         NSLog(@"%@", newName);
//     }];
    
    [self.nameTF.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
        NSLog(@"nameTF>> %@", x);
    }];
    
    [self.passwordTF.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
        NSLog(@"passwordTF>> %@", x);
    }];
    
    RACSignal *signal = [RACSignal combineLatest:@[self.nameTF.rac_textSignal, self.passwordTF.rac_textSignal]
                                          reduce:^(NSString *name, NSString *password) {
                                              return @(name.length >0 && password.length >0);
                                          }];
    
//    RAC(self, createEnabled) = signal;
//    [signal subscribeNext:^(id  _Nullable x) {
//        NSLog(@"signal>> %@", x);
//
//        self.loginButton.enabled = [x boolValue];
//    }];
     RAC(self.loginButton, enabled) = signal;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
